package com.taha.mail.service;

import java.sql.Connection;

import com.taha.mail.dbms.UserDataSource;
import com.taha.mail.dbms.UserDataSourceImp;
import com.taha.mail.entity.UserBean;
import com.taha.mail.exception.CreateAcountException;
import com.taha.mail.util.TahaDBSqlConnection;



public class UserServiceImp implements UserService<UserBean>{
	
	Connection conn = TahaDBSqlConnection.getConnInstance();
	
	@SuppressWarnings("rawtypes")
	UserDataSource userDatasource=new UserDataSourceImp();
	
	public boolean checkAvailibility(String userName){
		String[] userNames=userDatasource.getUserNames(conn);
		for(int i=0 ; i<userNames.length ; i++){
			if(userName.equals(userNames[i]))
				return false;//means that username is not available
		}
		
		return true;//means that user name is available
	}
	
	
	@SuppressWarnings("unchecked")
	public boolean CreateAcount(UserBean user)throws CreateAcountException{
		userDatasource.insert(conn,user);
		return true;
	}//end of createAcount method.

}
